# coding=utf-8
from selenium import webdriver
import time


# 创建webdriver对象
dr = webdriver.Chrome(r'/home/python/Desktop/chromedriver')
url = 'https://qzone.qq.com'
# 发送请求
dr.get(url)
time.sleep(5)
# el_log = dr.find_element_by_xpath('//*[@id="login_frame"]')
# 切换到嵌入的html框架(id='login_frame')
# dr.switch_to_frame(el_log)
# dr.switch_to_frame('login_frame')
dr.switch_to.frame('login_frame')
time.sleep(5)

# 定位到账户登录
el_c = dr.find_element_by_xpath('//*[@id="switcher_plogin"]')
# 点击
el_c.click()
# 定位到用户名
el_u = dr.find_element_by_xpath('//*[@id="u"]')
# 输入用户名
el_u.send_keys('*****')
# 定位到密码
el_p = dr.find_element_by_xpath('//*[@id="p"]')
# 输入密码
el_p.send_keys('*****')
# 定位到登录
el_sub = dr.find_element_by_xpath('//*[@id="login_button"]')
# 点击
el_sub.click()

# 窗口下拉
js = "window.scrollTo(0,{})"

for i in range(1, 10):
    time.sleep(2)
    # 每次下拉300像素
    comm = js.format(i*300)
    # 控制鼠标下拉
    dr.execute_script(comm)